//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CSimpleGeometry9.h>
///	@path	~/src/graphics/dx9/
///	@date	2007/10/25
///	@desc	.

#pragma once

#include "xeres.h"

#include "graphics/IGeometry.h"
#include "graphics/dx9/CDevice9.h"

namespace xeres {

	/*!
		\class	CSimpleGeometry9
		\brief	Very low-level and very basic implementation.
				Draws very simple geometry objects.
	*/
	class CSimpleGeometry9 : public IGeometry
	{
	public:

		/// \ctor
		CSimpleGeometry9( size_t stride , size_t count , D3DPRIMITIVETYPE type ,
			RefWeak<IVertexLayout> layout , IDirect3DVertexBuffer9 * vertex , IDirect3DIndexBuffer9 * index );

		/// \dtor
		virtual ~CSimpleGeometry9( void );

		DECL_IOBJECT_CLASS( CSimpleGeometry9 , IGeometry );

	public:

	//@ interface

		/*!
			\brief		Called when device is lost or before reset.
		*/
		virtual bool OnLostDevice( void );

		/*!
			\brief		Called after device is reset.
		*/
		virtual bool OnResetDevice( RefWeak<IDevice> device );

		/*! 
			\brief		Get geometry vertex layout.
		*/
		virtual RefWeak<IVertexLayout> GetLayout( void );

		/*! 
			\brief		Prepare draw (apply vertex & index buffer).
		*/
		virtual void EstablishBuffer( RenderContext& rc );

		/*!
			\brief		Draw geometry.
		*/
		virtual void Draw( RenderContext& rc );

	private:

	//@ data

		// vertex stride
		ushort						m_stride;

		// polygon is strip
		short						m_type;

		// primitive count
		size_t						m_count;

		//	directly access to buffer
		Ref<IVertexLayout>			m_layout;

		// vertex buffer
		IDirect3DVertexBuffer9 *	m_pVertexBuffer;

		// index buffer
		IDirect3DIndexBuffer9 *		m_pIndexBuffer;

	};

} // namespace xeres
